package com.kandinfo.base.admin.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kandinfo.base.admin.domain.DictData;
import com.kandinfo.base.admin.service.DictDataService;

@Controller
@RequestMapping(value="/dictdata")
public class DictDataController {
    
    @Autowired
    DictDataService dictDataService;

	
	@RequestMapping(value="/findByCode", method=RequestMethod.POST)
 	@ResponseBody
    public List<DictData> findByCode(String code){
 		return dictDataService.getByDefCode(code);
    }
	
	@RequestMapping(value="/findByCodes", method=RequestMethod.POST)
 	@ResponseBody
    public Map<String, List<DictData>> findByCodes(@RequestParam("codes[]") List<String> codes){
		Map<String, List<DictData>> map = new HashMap<String, List<DictData>>();
		for(String c : codes) {
			map.put(c, dictDataService.getByDefCode(c));
		}
 		return map;
    }
	
}
